package com.gxuwz.prrs.service.impl;

import com.google.gson.reflect.TypeToken;
import com.gxuwz.prrs.bean.CommonResponse;
import com.gxuwz.prrs.bean.Notice;
import com.gxuwz.prrs.bean.Page;
import com.gxuwz.prrs.service.BaseService;
import com.gxuwz.prrs.utils.RequestUtils;

import java.lang.reflect.Type;


/**
 * @author 张钧
 * @Description
 * @create 2023-05-24 上午 11:22
 */
public class NoticeServiceImpl implements BaseService<Notice,Page<Notice>> {
	Type type = new TypeToken<CommonResponse<Page<Notice>>>() {
	}.getType();

	@Override
	public Page<Notice> page(Page<Notice> page) {
		String url = "/notice/page?size=" + page.getSize() + "&current=" + page.getCurrent();
		CommonResponse<Page<Notice>> response = RequestUtils.getRequest(url, type);
		if (response != null) {
			return response.getData();
		}
		return null;
	}

	public Notice lastNotice() {
		String url = "/notice/page?size=1&current=1";
		CommonResponse<Page<Notice>> response = RequestUtils.getRequest(url, type);
		if (response != null) {
			return response.getData().getRecords().get(0);
		}
		return null;
	}
}
